package com.chen.utils;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import org.springframework.jdbc.datasource.embedded.DataSourceFactory;

import javax.sql.DataSource;

/**
 * ClassName: MyBatisCodeGenerator
 * Package: com.chen.utils
 * Description:
 *
 * @Author 陈俊辉
 * @Create 2024/4/10 8:57
 * @Version 1.0
 */

public class MyBatisPlusUtils {
    /**
     * 自动代码生成器
     */

        /**
         * 自动代码生成器
         */
        public static void autoCodeGenerator() {

            FastAutoGenerator
                    //数据源配置
                    .create(new DataSourceConfig.Builder("jdbc:mysql://127.0.0.1:3306/itcast", "root", "1234"))
                    // 全局配置
                    .globalConfig(builder -> {
                        builder.fileOverride()
                                //配置项目的位置
                                .outputDir("E:\\Code\\demo\\itcast-web-manager\\src\\main\\java")
                                .author("chen")
                                //开启swagger,如果有使用需要添加依赖
                                .enableSwagger()
                                .dateType(DateType.TIME_PACK)
                                .commentDate("yyyy-MM-dd");

                    })
                    // 包配置
                    .packageConfig(builder -> {
                        builder.parent("com.chen")
                                .entity("pojo")
                                .service("service")
                                .serviceImpl("service.impl")
                                .mapper("mapper")
                                .xml("mapper.xml")
                                .controller("controller");
                    })
                    // 策略配置
                    .strategyConfig(
                            builder -> {
                                builder
                                        //命名时候的大小写转化(表名)
                                        .enableCapitalMode()
                                        .enableSkipView()
                                        .addInclude("dept", "emp");
                            }
                    )
                    //实体类策略
                    .strategyConfig(builder -> {
                        builder.entityBuilder()
                                .enableLombok()
                                .enableChainModel()
                                //开启注解
                                .enableTableFieldAnnotation();
                    })
                    .execute();


        }






    public static void main(String[] args) {
        autoCodeGenerator();
    }
}
